
Imports System
Imports System.Collections
Imports System.Text

Imports PrintDoc2Pdf.sharpPDF.Exceptions
Imports PrintDoc2Pdf.sharpPDF.Enumerators

Namespace sharpPDF
    ''' <summary>
    ''' Abstract class that implements different functions used for text and paragraph
    ''' </summary>
    Friend MustInherit Class textAdapter

        'Helvetica			
        'HelveticaBold
        'csHelveticaOblique
        'csHelvetivaBoldOblique
        'Courier			
        'csCourierBold
        'csCourierOblique
        'csCourierBoldOblique
        'csTimes
        'csTimesBold
        'csTimesOblique
        'csTimesBoldOblique
        ''' <summary>
        ''' Static property with the dimensions of the standard fonts
        ''' </summary>
        Private Shared fontWeight As Integer(,) = New Integer(11, 255) {{278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 355, 556, _
           556, 889, 667, 191, 333, 333, _
           389, 584, 278, 333, 278, 278, _
           556, 556, 556, 556, 556, 556, _
           556, 556, 556, 556, 278, 278, _
           584, 584, 584, 556, 1015, 667, _
           667, 722, 722, 667, 611, 778, _
           722, 278, 500, 667, 556, 833, _
           722, 778, 667, 778, 722, 667, _
           611, 722, 667, 944, 667, 667, _
           611, 278, 278, 278, 469, 556, _
           333, 556, 556, 500, 556, 556, _
           278, 556, 556, 222, 222, 500, _
           222, 833, 556, 556, 556, 556, _
           333, 500, 278, 556, 500, 722, _
           500, 500, 500, 334, 260, 334, _
           584, 350, 556, 350, 222, 556, _
           333, 1000, 556, 556, 333, 1000, _
           667, 333, 1000, 350, 611, 350, _
           350, 222, 222, 333, 333, 350, _
           556, 1000, 333, 1000, 500, 333, _
           944, 350, 500, 667, 278, 333, _
           556, 556, 556, 556, 260, 556, _
           333, 737, 370, 556, 584, 333, _
           737, 333, 400, 584, 333, 333, _
           333, 556, 537, 278, 333, 333, _
           365, 556, 834, 834, 834, 611, _
           667, 667, 667, 667, 667, 667, _
           1000, 722, 667, 667, 667, 667, _
           278, 278, 278, 278, 722, 722, _
           778, 778, 778, 778, 778, 584, _
           778, 722, 722, 722, 722, 667, _
           667, 611, 556, 556, 556, 556, _
           556, 556, 889, 500, 556, 556, _
           556, 556, 278, 278, 278, 278, _
           556, 556, 556, 556, 556, 556, _
           556, 584, 611, 556, 556, 556, _
           556, 500, 556, 500}, {278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 333, 474, 556, _
           556, 889, 722, 238, 333, 333, _
           389, 584, 278, 333, 278, 278, _
           556, 556, 556, 556, 556, 556, _
           556, 556, 556, 556, 333, 333, _
           584, 584, 584, 611, 975, 722, _
           722, 722, 722, 667, 611, 778, _
           722, 278, 556, 722, 611, 833, _
           722, 778, 667, 778, 722, 667, _
           611, 722, 667, 944, 667, 667, _
           611, 333, 278, 333, 584, 556, _
           333, 556, 611, 556, 611, 556, _
           333, 611, 611, 278, 278, 556, _
           278, 889, 611, 611, 611, 611, _
           389, 556, 333, 611, 556, 778, _
           556, 556, 500, 389, 280, 389, _
           584, 350, 556, 350, 278, 556, _
           500, 1000, 556, 556, 333, 1000, _
           667, 333, 1000, 350, 611, 350, _
           350, 278, 278, 500, 500, 350, _
           556, 1000, 333, 1000, 556, 333, _
           944, 350, 500, 667, 278, 333, _
           556, 556, 556, 556, 280, 556, _
           333, 737, 370, 556, 584, 333, _
           737, 333, 400, 584, 333, 333, _
           333, 611, 556, 278, 333, 333, _
           365, 556, 834, 834, 834, 611, _
           722, 722, 722, 722, 722, 722, _
           1000, 722, 667, 667, 667, 667, _
           278, 278, 278, 278, 722, 722, _
           778, 778, 778, 778, 778, 584, _
           778, 722, 722, 722, 722, 667, _
           667, 611, 556, 556, 556, 556, _
           556, 556, 889, 556, 556, 556, _
           556, 556, 278, 278, 278, 278, _
           611, 611, 611, 611, 611, 611, _
           611, 584, 611, 611, 611, 611, _
           611, 556, 611, 556}, {278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 355, 556, _
           556, 889, 667, 191, 333, 333, _
           389, 584, 278, 333, 278, 278, _
           556, 556, 556, 556, 556, 556, _
           556, 556, 556, 556, 278, 278, _
           584, 584, 584, 556, 1015, 667, _
           667, 722, 722, 667, 611, 778, _
           722, 278, 500, 667, 556, 833, _
           722, 778, 667, 778, 722, 667, _
           611, 722, 667, 944, 667, 667, _
           611, 278, 278, 278, 469, 556, _
           333, 556, 556, 500, 556, 556, _
           278, 556, 556, 222, 222, 500, _
           222, 833, 556, 556, 556, 556, _
           333, 500, 278, 556, 500, 722, _
           500, 500, 500, 334, 260, 334, _
           584, 350, 556, 350, 222, 556, _
           333, 1000, 556, 556, 333, 1000, _
           667, 333, 1000, 350, 611, 350, _
           350, 222, 222, 333, 333, 350, _
           556, 1000, 333, 1000, 500, 333, _
           944, 350, 500, 667, 278, 333, _
           556, 556, 556, 556, 260, 556, _
           333, 737, 370, 556, 584, 333, _
           737, 333, 400, 584, 333, 333, _
           333, 556, 537, 278, 333, 333, _
           365, 556, 834, 834, 834, 611, _
           667, 667, 667, 667, 667, 667, _
           1000, 722, 667, 667, 667, 667, _
           278, 278, 278, 278, 722, 722, _
           778, 778, 778, 778, 778, 584, _
           778, 722, 722, 722, 722, 667, _
           667, 611, 556, 556, 556, 556, _
           556, 556, 889, 500, 556, 556, _
           556, 556, 278, 278, 278, 278, _
           556, 556, 556, 556, 556, 556, _
           556, 584, 611, 556, 556, 556, _
           556, 500, 556, 500}, {278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 278, 278, 278, _
           278, 278, 278, 333, 474, 556, _
           556, 889, 722, 238, 333, 333, _
           389, 584, 278, 333, 278, 278, _
           556, 556, 556, 556, 556, 556, _
           556, 556, 556, 556, 333, 333, _
           584, 584, 584, 611, 975, 722, _
           722, 722, 722, 667, 611, 778, _
           722, 278, 556, 722, 611, 833, _
           722, 778, 667, 778, 722, 667, _
           611, 722, 667, 944, 667, 667, _
           611, 333, 278, 333, 584, 556, _
           333, 556, 611, 556, 611, 556, _
           333, 611, 611, 278, 278, 556, _
           278, 889, 611, 611, 611, 611, _
           389, 556, 333, 611, 556, 778, _
           556, 556, 500, 389, 280, 389, _
           584, 350, 556, 350, 278, 556, _
           500, 1000, 556, 556, 333, 1000, _
           667, 333, 1000, 350, 611, 350, _
           350, 278, 278, 500, 500, 350, _
           556, 1000, 333, 1000, 556, 333, _
           944, 350, 500, 667, 278, 333, _
           556, 556, 556, 556, 280, 556, _
           333, 737, 370, 556, 584, 333, _
           737, 333, 400, 584, 333, 333, _
           333, 611, 556, 278, 333, 333, _
           365, 556, 834, 834, 834, 611, _
           722, 722, 722, 722, 722, 722, _
           1000, 722, 667, 667, 667, 667, _
           278, 278, 278, 278, 722, 722, _
           778, 778, 778, 778, 778, 584, _
           778, 722, 722, 722, 722, 667, _
           667, 611, 556, 556, 556, 556, _
           556, 556, 889, 556, 556, 556, _
           556, 556, 278, 278, 278, 278, _
           611, 611, 611, 611, 611, 611, _
           611, 584, 611, 611, 611, 611, _
           611, 556, 611, 556}, {600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600}, {600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600}, _
           {600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600}, {600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600, 600, 600, _
           600, 600, 600, 600}, {250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 333, 408, 500, _
           500, 833, 778, 180, 333, 333, _
           500, 564, 250, 333, 250, 278, _
           500, 500, 500, 500, 500, 500, _
           500, 500, 500, 500, 278, 278, _
           564, 564, 564, 444, 921, 722, _
           667, 667, 722, 611, 556, 722, _
           722, 333, 389, 722, 611, 889, _
           722, 722, 556, 722, 667, 556, _
           611, 722, 722, 944, 722, 722, _
           611, 333, 278, 333, 469, 500, _
           333, 444, 500, 444, 500, 444, _
           333, 500, 500, 278, 278, 500, _
           278, 778, 500, 500, 500, 500, _
           333, 389, 278, 500, 500, 722, _
           500, 500, 444, 480, 200, 480, _
           541, 350, 500, 350, 333, 500, _
           444, 1000, 500, 500, 333, 1000, _
           556, 333, 889, 350, 611, 350, _
           350, 333, 333, 444, 444, 350, _
           500, 1000, 333, 980, 389, 333, _
           722, 350, 444, 722, 250, 333, _
           500, 500, 500, 500, 200, 500, _
           333, 760, 276, 500, 564, 333, _
           760, 333, 400, 564, 300, 300, _
           333, 500, 453, 250, 333, 300, _
           310, 500, 750, 750, 750, 444, _
           722, 722, 722, 722, 722, 722, _
           889, 667, 611, 611, 611, 611, _
           333, 333, 333, 333, 722, 722, _
           722, 722, 722, 722, 722, 564, _
           722, 722, 722, 722, 722, 722, _
           556, 500, 444, 444, 444, 444, _
           444, 444, 667, 444, 444, 444, _
           444, 444, 278, 278, 278, 278, _
           500, 500, 500, 500, 500, 500, _
           500, 564, 500, 500, 500, 500, _
           500, 500, 500, 500}, {250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 333, 555, 500, _
           500, 1000, 833, 278, 333, 333, _
           500, 570, 250, 333, 250, 278, _
           500, 500, 500, 500, 500, 500, _
           500, 500, 500, 500, 333, 333, _
           570, 570, 570, 500, 930, 722, _
           667, 722, 722, 667, 611, 778, _
           778, 389, 500, 778, 667, 944, _
           722, 778, 611, 778, 722, 556, _
           667, 722, 722, 1000, 722, 722, _
           667, 333, 278, 333, 581, 500, _
           333, 500, 556, 444, 556, 444, _
           333, 500, 556, 278, 333, 556, _
           278, 833, 556, 500, 556, 556, _
           444, 389, 333, 556, 500, 722, _
           500, 500, 444, 394, 220, 394, _
           520, 350, 500, 350, 333, 500, _
           500, 1000, 500, 500, 333, 1000, _
           556, 333, 1000, 350, 667, 350, _
           350, 333, 333, 500, 500, 350, _
           500, 1000, 333, 1000, 389, 333, _
           722, 350, 444, 722, 250, 333, _
           500, 500, 500, 500, 220, 500, _
           333, 747, 300, 500, 570, 333, _
           747, 333, 400, 570, 300, 300, _
           333, 556, 540, 250, 333, 300, _
           330, 500, 750, 750, 750, 500, _
           722, 722, 722, 722, 722, 722, _
           1000, 722, 667, 667, 667, 667, _
           389, 389, 389, 389, 722, 722, _
           778, 778, 778, 778, 778, 570, _
           778, 722, 722, 722, 722, 722, _
           611, 556, 500, 500, 500, 500, _
           500, 500, 722, 444, 444, 444, _
           444, 444, 278, 278, 278, 278, _
           500, 556, 500, 500, 500, 500, _
           500, 570, 500, 556, 556, 556, _
           556, 500, 556, 500}, {250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 333, 420, 500, _
           500, 833, 778, 214, 333, 333, _
           500, 675, 250, 333, 250, 278, _
           500, 500, 500, 500, 500, 500, _
           500, 500, 500, 500, 333, 333, _
           675, 675, 675, 500, 920, 611, _
           611, 667, 722, 611, 611, 722, _
           722, 333, 444, 667, 556, 833, _
           667, 722, 611, 722, 611, 500, _
           556, 722, 611, 833, 611, 556, _
           556, 389, 278, 389, 422, 500, _
           333, 500, 500, 444, 500, 444, _
           278, 500, 500, 278, 278, 444, _
           278, 722, 500, 500, 500, 500, _
           389, 389, 278, 500, 444, 667, _
           444, 444, 389, 400, 275, 400, _
           541, 350, 500, 350, 333, 500, _
           556, 889, 500, 500, 333, 1000, _
           500, 333, 944, 350, 556, 350, _
           350, 333, 333, 556, 556, 350, _
           500, 889, 333, 980, 389, 333, _
           667, 350, 389, 556, 250, 389, _
           500, 500, 500, 500, 275, 500, _
           333, 760, 276, 500, 675, 333, _
           760, 333, 400, 675, 300, 300, _
           333, 500, 523, 250, 333, 300, _
           310, 500, 750, 750, 750, 500, _
           611, 611, 611, 611, 611, 611, _
           889, 667, 611, 611, 611, 611, _
           333, 333, 333, 333, 722, 667, _
           722, 722, 722, 722, 722, 675, _
           722, 722, 722, 722, 722, 556, _
           611, 500, 500, 500, 500, 500, _
           500, 500, 667, 444, 444, 444, _
           444, 444, 278, 278, 278, 278, _
           500, 500, 500, 500, 500, 500, _
           500, 675, 500, 500, 500, 500, _
           500, 444, 500, 444}, {250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 250, 250, 250, _
           250, 250, 250, 389, 555, 500, _
           500, 833, 778, 278, 333, 333, _
           500, 570, 250, 333, 250, 278, _
           500, 500, 500, 500, 500, 500, _
           500, 500, 500, 500, 333, 333, _
           570, 570, 570, 500, 832, 667, _
           667, 667, 722, 667, 667, 722, _
           778, 389, 500, 667, 611, 889, _
           722, 722, 611, 722, 667, 556, _
           611, 722, 667, 889, 667, 611, _
           611, 333, 278, 333, 570, 500, _
           333, 500, 500, 444, 500, 444, _
           333, 500, 556, 278, 278, 500, _
           278, 778, 556, 500, 500, 500, _
           389, 389, 278, 556, 444, 667, _
           500, 444, 389, 348, 220, 348, _
           570, 350, 500, 350, 333, 500, _
           500, 1000, 500, 500, 333, 1000, _
           556, 333, 944, 350, 611, 350, _
           350, 333, 333, 500, 500, 350, _
           500, 1000, 333, 1000, 389, 333, _
           722, 350, 389, 611, 250, 389, _
           500, 500, 500, 500, 220, 500, _
           333, 747, 266, 500, 606, 333, _
           747, 333, 400, 570, 300, 300, _
           333, 576, 500, 250, 333, 300, _
           300, 500, 750, 750, 750, 500, _
           667, 667, 667, 667, 667, 667, _
           944, 667, 667, 667, 667, 667, _
           389, 389, 389, 389, 722, 722, _
           722, 722, 722, 722, 722, 570, _
           722, 722, 722, 722, 722, 611, _
           611, 500, 500, 500, 500, 500, _
           500, 500, 722, 444, 444, 444, _
           444, 444, 278, 278, 278, 278, _
           500, 556, 500, 500, 500, 500, _
           500, 570, 500, 556, 556, 556, _
           556, 444, 500, 444}}


        ''' <summary>
        ''' Static method that encodes the string
        ''' </summary>
        ''' <param name="strText">Input Text</param>
        ''' <returns>Result of the encoding</returns>
        Public Shared Function encodeHEX(ByVal strText As String) As String
            Dim arrChar As Char() = strText.ToCharArray()
            Dim hexFormattedString As String = ""
            Dim appoStr As String
            Dim i As Integer = 0
            While i < arrChar.Length
                If (Asc(arrChar(i)) >= 0) AndAlso (Asc(arrChar(i)) <= 255) Then
                    appoStr = (Convert.ToByte(arrChar(i))).ToString("X")
                    If appoStr.Length < 2 Then
                        appoStr = "0" + appoStr
                    End If
                    hexFormattedString += appoStr
                End If
                System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
            End While
            Return hexFormattedString
        End Function

        ''' <summary>
        ''' Static method that checks special characters into a string
        ''' </summary>
        ''' <param name="strText">Input Text</param>
        ''' <returns>Formatted Text</returns>
        Public Shared Function checkText(ByVal strText As String) As String
            Dim checkedString As String = strText
            checkedString = checkedString.Replace("\", "\\")
            checkedString = checkedString.Replace("(", "\(")
            checkedString = checkedString.Replace(")", "\)")
            Return checkedString
        End Function

        ''' <summary>
        ''' Static method thats format a paragraph
        ''' </summary>
        ''' <param name="strText">Input Text</param>
        ''' <param name="fontSize">Font's size</param>
        ''' <param name="fontType">Font's type</param>
        ''' <param name="parWidth">Paragrapfh's width</param>
        ''' <returns>IEnumerable interface that cointains paragraphLine objects</returns>
        Public Shared Function formatParagraph(ByVal strText As String, ByVal fontSize As Integer, ByVal fontType As predefinedFont, ByVal parWidth As Integer) As IEnumerable
            Return formatParagraph(strText, fontSize, fontType, parWidth, fontSize + 4, predefinedAlignment.csLeft)
        End Function

        ''' <summary>
        ''' Static method thats format a paragraph
        ''' </summary>
        ''' <param name="strText">Input Text</param>
        ''' <param name="fontSize">Font's size</param>
        ''' <param name="fontType">Font's type</param>
        ''' <param name="parWidth">Paragrapfh's width</param>
        ''' <param name="lineHeight">Line's height</param>
        ''' <returns>IEnumerable interface that cointains paragraphLine objects</returns>
        Public Shared Function formatParagraph(ByVal strText As String, ByVal fontSize As Integer, ByVal fontType As predefinedFont, ByVal parWidth As Integer, ByVal lineHeight As Integer) As IEnumerable
            Return formatParagraph(strText, fontSize, fontType, parWidth, lineHeight, predefinedAlignment.csLeft)
        End Function

        ''' <summary>
        ''' Static method thats format a paragraph
        ''' </summary>
        ''' <param name="strText">Input Text</param>
        ''' <param name="fontSize">Font's size</param>
        ''' <param name="fontType">Font's type</param>
        ''' <param name="parWidth">Paragrapfh's width</param>
        ''' <param name="lineHeight">Line's height</param>
        ''' <param name="parAlign">Paragraph's Alignment</param>
        ''' <returns>IEnumerable interface that cointains paragraphLine objects</returns>
        Public Shared Function formatParagraph(ByVal strText As String, ByVal fontSize As Integer, ByVal fontType As predefinedFont, ByVal parWidth As Integer, ByVal lineHeight As Integer, ByVal parAlign As predefinedAlignment) As IEnumerable
            Dim paragraphsArray As String() = strText.Split(("" & Chr(10) & "").ToCharArray())
            Dim bufferArray As String()
            Dim lineLength As Integer
            Dim tempPar As paragraphLine = Nothing
            Dim lineString As New StringBuilder(parWidth)
            Dim resultArray As New ArrayList()
            lineLength = 0
            For Each paragraph As String In paragraphsArray
                bufferArray = paragraph.Split(" ".ToCharArray())
                For Each word As String In bufferArray
                    If (textAdapter.wordWeight(word + " ", fontSize, fontType) + lineLength) > parWidth Then
                        Select Case parAlign
                            Case predefinedAlignment.csLeft
                                tempPar = New paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, 0)
                            Case predefinedAlignment.csRight
                                tempPar = New paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, parWidth - lineLength)
                            Case predefinedAlignment.csCenter
                                tempPar = New paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, Convert.ToInt32((parWidth - lineLength) / 2))
                        End Select
                        resultArray.Add(tempPar)
                        lineString.Remove(0, lineString.Length)
                        lineLength = 0
                    End If
                    lineString.Append(word + " ")
                    lineLength += textAdapter.wordWeight(word + " ", fontSize, fontType)
                Next
                If lineLength > 0 Then
                    Select Case parAlign
                        Case predefinedAlignment.csLeft
                            tempPar = New paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, 0)
                        Case predefinedAlignment.csRight
                            tempPar = New paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, parWidth - lineLength)
                        Case predefinedAlignment.csCenter
                            tempPar = New paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, Convert.ToInt32((parWidth - lineLength) / 2))
                    End Select
                    resultArray.Add(tempPar)
                    lineString.Remove(0, lineString.Length)
                    lineLength = 0
                End If
                bufferArray = Nothing
            Next
            Return resultArray
        End Function

        ''' <summary>
        ''' Static Method that returns the lenght of a single word
        ''' </summary>
        ''' <param name="word">Input word</param>
        ''' <param name="fontSize">Font's size</param>
        ''' <param name="fontType">Font's type</param>
        ''' <returns>Size of the word</returns>
        Public Shared Function wordWeight(ByVal word As String, ByVal fontSize As Integer, ByVal fontType As predefinedFont) As Integer
            Dim returnWeight As Double = 0
            For Each myChar As Char In word.ToCharArray()
                If (Asc(myChar) >= 0) AndAlso (Asc(myChar) <= 255) Then
                    returnWeight += textAdapter.fontWeight(CInt(fontType) - 1, Convert.ToByte(myChar))
                End If
            Next
            Return Convert.ToInt32(returnWeight * fontSize / 1000)
        End Function

        ''' <summary>
        ''' Static Method that crop a word to put it in a predefined space
        ''' </summary>
        ''' <param name="word">Input word</param>
        ''' <param name="fontSize">Font's size</param>
        ''' <param name="fontType">Font's type</param>
        ''' <param name="textSpace">Max text's space</param>
        ''' <returns>Cropped word</returns>
        Public Shared Function cropWord(ByVal word As String, ByVal fontSize As Integer, ByVal fontType As predefinedFont, ByVal textSpace As Integer) As String
            Dim tempWord As New StringBuilder()
            Dim i As Integer = 0
            While (wordWeight(tempWord.ToString(), fontSize, fontType) <= textSpace) AndAlso (i < word.Length)
                If (asc(word(i)) >= 0) AndAlso (asc(word(i)) <= 255) Then
                    tempWord.Append(word.ToCharArray()(i))
                End If
                System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
            End While
            If tempWord.ToString().CompareTo(word) <> 0 Then
                tempWord.Remove(tempWord.Length - 3, 3)
                tempWord.Append("...")
            End If
            Return tempWord.ToString()
        End Function
    End Class
End Namespace

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Built and maintained by Todd Anglin and Telerik
'=======================================================
